package com.zgkxzx.java.mutilThread.dcl;

import java.util.Random;

/**
 * 创建者 zgkxzx
 * 日期   1/11/18
 * 描述
 */

/**
 * DCL即双重检查加锁，关于单例模式的DCL机制，可以参看：http://blog.csdn.net/ns_code/article/details/17359719
 */

public class Singleston {

    private static Singleston instance;

    private int value;

    private Singleston() {
        value = new Random().nextInt(100) + 5;
    }

    public static Singleston getInstance() {
        if (instance == null) {
            synchronized (Singleston.class) {
                if (instance == null)
                    instance = new Singleston();
            }
        }
        return instance;
    }

    public int getValue() {
        return value;
    }


}
